package com.java.dao.impl;

import java.sql.*;

/**
 * Student Dao 层
 *
 * @author 村头老杨头
 * @version 1.0
 * @date 2021/9/26 15:33
 */
public class StudentDaoImpl {
    private String url = "jdbc:mysql://127.0.0.1:3306/edu";
    private String username = "root";
    private String password = "123456";
    public void getSutdentById(String sno) throws ClassNotFoundException, SQLException {
        //1.加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //2.创建连接
        Connection conn = DriverManager.getConnection(url, username, password);
        //3.创建Statement
        String sql="select * from student where sno="+sno;
        Statement st = conn.createStatement();
        //4.发送SQL语句并返回结果集
        ResultSet rs = st.executeQuery(sql);
        //5.解析结果集
        while (rs.next()){
            //rs.getString(1) String 是数据库中字段的类型 1 第一列数据
            System.out.println(rs.getString(1)+"\t"+rs.getString("Sname")+"\t"+rs.getObject("Ssex")+"\t"+rs.getDate("Sbirthday")+"\t"+rs.getString("Clazz"));
        }
        //6.关闭资源
        rs.close();
        st.close();
        conn.close();
    }
}
